package cn.itcast.bos.action.base;

import java.util.HashMap;


import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.base.StandardService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
@Scope("prototype")
@ParentPackage("json-default")
@Namespace("/")
public class StandardAction extends BaseAction<Standard>{
	
	@Autowired
	private StandardService standardService;
	//          /bos_management/standardSave          
	//       /bos_management/     /pages/base/standard.html   ../../js
	@Action(value="standardSave",results={@Result(name="success", type="redirect", location="/pages/base/standard.html")})
	public String standardSave(){
		
		standardService.save(model);
		
		return SUCCESS;
	}
	
	@Action(value="queryPage",results={@Result(name="success",type="json")})
	public String querPage(){
		
	Pageable pageable = new PageRequest(page-1, rows);
	
	Page<Standard> page = standardService.queryPage(pageable);
	pushPageDataToValueStack(page);
	return SUCCESS;
	}
	
	@Action(value="standardName",results={@Result(name="success",type="json")})
	public String standardFindName(){
		
	List<Standard> list = standardService.findAll();
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}

}
